package org.lsc.lesson4configclient.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author 刘事成
 * @Date 2018/10/11
 * @Time 9:50
 * @Description:研究系列
 */
public class PropertySourceLocator implements EnvironmentPostProcessor {

    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        //远程获取配置
        Map<String, String> propertyMap = new HashMap<>();
        propertyMap.put("spring.application.name", "config-client");
        propertyMap.put("spring.cloud.config.uri", "http://localhost:10002/");
        propertyMap.put("spring.cloud.config.profile", "stage");
        propertyMap.put("spring.cloud.config.label", "master");
        propertyMap.put("management.security.enabled", "false");
        PropertySource propertySource = new PropertySource("sys-config",propertyMap);
        environment.getPropertySources().addFirst(propertySource);
    }
}
